package com.koo.common.utils;

import com.koo.common.vo.UserVo;

public class UserUtils {

    private UserUtils(){}
	// 这里是ThreadLocal，需要有user实体
    private static final ThreadLocal<UserVo> USER = new ThreadLocal<UserVo>();

    public static void set(UserVo userInfo) {
        USER.set(userInfo);
    }

    public static UserVo get() {
        return USER.get();
    }
	// 方便使用后移除ThreadLocal
    public static void remove() {
        USER.remove();
    }

    public static String getUsername() {
        if(USER.get() != null){
            return USER.get().getUsername();
        }
        return null;
    }

    public static Long getUserId() {
        if(USER.get() != null){
            return USER.get().getUserId();
        }
        return null;
    }

    public static Long getStoreId() {
        if(USER.get() != null){
            return USER.get().getStoreId();
        }
        return null;
    }

    public static String getStoreCode() {
        if(USER.get() != null){
            return USER.get().getStoreCode();
        }
        return null;
    }

}
